package me.notfirecodes.serverpatcher.cmds;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CustomMaxHealthCMD implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args){

        if(sender instanceof Player){
            if(args.length > 0){
                Player player = (Player) sender;
                if(player.hasPermission("serverpatcher.maxhealth")){
                    player.setMaxHealth(Double.parseDouble(args[0]));
                    player.setHealth(Double.parseDouble(args[0]));
                    player.sendMessage(ChatColor.GREEN + "Your health was set!");
                }
                else{
                    player.sendMessage(ChatColor.RED + "You do not have permission to run this command.");
                }
            }
            else{
                Player player = (Player) sender;
                player.sendMessage(ChatColor.RED + "You need to specify a number!:");
                player.sendMessage(ChatColor.RED + "/cmaxhealth [number]");
            }
        }
        else{
            System.out.println(ChatColor.RED + "You cannot run this command with console!");
        }
    return true;
    }
}
